<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 
            合并二叉树看起来难其实很简单，就是同时遍历两个树即可.
            但是注意一个细节，如果root1不存在，那么并不一定就是空，需要返回root2
            */
            var mergeTrees = function (root1, root2) {
                if (!root1) return root2 //如果root1为空，返回的是root2
                if (!root2) return root1
                let root = new TreeNode(root1.val + root2.val)
                root.left = mergeTrees(root1.left, root2.left)
                root.right = mergeTrees(root1.right, root2.right)
                return root
            }
        </script>
    </body>
</html>
